//
// Created by sjjmw on 3/24/2022.
//
#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"

//cin>>string
void handle(int n){
    std::string line;
    std::getline(std::cin,line);
    for(int i=0;i<n;i++){
//        std::string line;
        std::getline(std::cin,line);
        bool last_space= true;
        int cnt=0;
        for(auto c:line){
            if(c==' '){
                last_space= true;
            }else{
                if(last_space){
                    cnt++;
                }
                last_space= false;
            }
        }
        printf("%d\n",cnt);
    }
    ;
}

int main(){
    int a,b;
    while(std::cin>>a){
        handle(a);
    }
    return 0;
}